function comparePages() {
    const width = Math.min(canvas1.width, canvas2.width);
    const height = Math.min(canvas1.height, canvas2.height);

    diffCanvas.width = width;
    diffCanvas.height = height;

    const imageData1 = ctx1.getImageData(0, 0, width, height);
    const imageData2 = ctx2.getImageData(0, 0, width, height);
    const diffImageData = diffCtx.createImageData(width, height);

    let diffCount = 0;

    function getAverageColor(imageData, x, y, size) {
        let r = 0, g = 0, b = 0, count = 0;
        const radius = Math.floor(size / 2);
        
        for (let dy = -radius; dy <= radius; dy++) {
            for (let dx = -radius; dx <= radius; dx++) {
                const nx = x + dx;
                const ny = y + dy;
                if (nx >= 0 && nx < width && ny >= 0 && ny < height) {
                    const i = (ny * width + nx) * 4;
                    r += imageData.data[i];
                    g += imageData.data[i + 1];
                    b += imageData.data[i + 2];
                    count++;
                }
            }
        }
        return {
            r: r / count,
            g: g / count,
            b: b / count
        };
    }

    for (let y = 0; y < height; y++) {
        for (let x = 0; x < width; x++) {
            const i = (y * width + x) * 4;
            
            const color1 = getAverageColor(imageData1, x, y, blurLevel * 2 + 1);
            const color2 = getAverageColor(imageData2, x, y, blurLevel * 2 + 1);

            const diffR = Math.abs(color1.r - color2.r);
            const diffG = Math.abs(color1.g - color2.g);
            const diffB = Math.abs(color1.b - color2.b);

            if (diffR > diffThreshold || diffG > diffThreshold || diffB > diffThreshold) {
                diffCount++;
                diffImageData.data[i] = 255;
                diffImageData.data[i + 1] = 0;
                diffImageData.data[i + 2] = 0;
                diffImageData.data[i + 3] = 128;
            } else {
                diffImageData.data[i] = imageData1.data[i];
                diffImageData.data[i + 1] = imageData1.data[i + 1];
                diffImageData.data[i + 2] = imageData1.data[i + 2];
                diffImageData.data[i + 3] = imageData1.data[i + 3];
            }
        }
    }

    diffCtx.drawImage(canvas1, 0, 0);
    diffCtx.putImageData(diffImageData, 0, 0);

    const totalPixels = width * height;
    const diffPercentage = (diffCount / totalPixels) * 100;
    
    debugInfo.innerHTML = '';
    log(`当前对比：第 ${currentPage1} 页 vs 第 ${currentPage2} 页`);
    log(`页面尺寸: ${width} x ${height} 像素`);
    log(`发现差异: ${diffCount} 个像素`);
    log(`差异比例: ${diffPercentage.toFixed(2)}%`);
    if (diffCount > 0) {
        log('红色半透明区域表示差异部分');
    }
} 